#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#include <vector>
#include <string.h>
using namespace std;

struct edge
{
    int v;
    int c;
};
const int maxn = 1e5 + 10;

vector<edge> g[maxn];

int n, m, c;
int u, v, vi;

void query(int node)
{
    bool vis[maxn] = {0};
    map<int, int> mp;
    queue<int> q;
    long long ans = 0;
    q.push(node);
    vis[node] = true;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = 0; i < g[u].size(); i++)
        {
            auto temp = g[u][i];
            if (!vis[temp.v] && temp.c <= c)
            {
                mp[temp.c]++;
                q.push(temp.v);
                vis[temp.v] = true;
            }
        }
    }
    for (auto &p : mp)
    {
        ans += (p.first * p.second) * (p.first * p.second);
    }
    cout << ans << endl;
}

int main()
{
    cin >> n >> m >> c;
    for (int i = 1; i <= n - 1; i++)
    {
        cin >> u >> v >> vi;
        g[u].push_back({v, vi});
    }
    for (int i = 1; i <= m; i++)
    {
        int q;
        cin >> q;
        query(q);
    }
    // system("pause");
    return 0;
}